<template>
  <div
    class="equipment-record content bg-white full-height page-content padding-b-20"
  >
    <collapse ref="collapse">
      <template v-slot:content>
        <div
          class="form-inline bottom"
          style="justify-content: space-between; padding-top: 6px;padding-bottom: 0"
        >
          <div class="left box" style="display: flex">
            <div class="row" style="max-width: 1500px">
              <select-tree
                v-if="show"
                label="所在位置"
                :sel-tree="queryParams.location"
                class="margin-r-15 margin-b-20"
                ref="selectTree"
                :tree-list="locationOptions"
                node-key="hash"
                @treeChange="_changeTreeNode"
              />
              <q-select
                class="select margin-r-15 margin-b-20"
                outlined
                dense
                emit-value
                map-options
                options-dense
                :options="stationOptions"
                v-model="queryParams.station"
              >
                <template v-slot:no-option>
                  <div class="no-option" />
                </template>
                <template v-slot:before>
                  <span class="form-name">工位:</span>
                </template>
              </q-select>
              <q-select
                class="select margin-r-15 margin-b-20"
                outlined
                dense
                emit-value
                map-options
                options-dense
                :options="equipmentTypeOptions"
                v-model="queryParams.equipmentType"
              >
                <template v-slot:no-option>
                  <div class="no-option" />
                </template>
                <template v-slot:before>
                  <span class="form-name">设备类型:</span>
                </template>
              </q-select>
              <q-select
                class="select margin-r-15 margin-b-20"
                outlined
                dense
                emit-value
                map-options
                options-dense
                :options="enabledOptions"
                v-model="queryParams.enabled"
              >
                <template v-slot:no-option>
                  <div class="no-option" />
                </template>
                <template v-slot:before>
                  <span class="form-name">启用状态:</span>
                </template>
              </q-select>
            </div>
          </div>
          <div style="display: flex">
            <q-btn
              class="btn margin-r-10"
              outline
              color="primary"
              @click="resetSearch"
              label="重置"
            />
            <q-btn
              class="btn"
              unelevated
              type="submit"
              color="primary"
              label="查询"
              @click="
                pagination.page = 1;
                getList();
              "
            />
          </div>
        </div>
        <div
          class="form-inline bottom"
          style="justify-content: space-between;padding-bottom: 20px"
        >
          <div class="left box">
            <q-btn
              v-has="{ id: Enums.SYS_PERMISSION.DEL_DEVICE_BTN.value }"
              class="btn margin-r-10"
              outline
              color="primary"
              @click="batchDeletion"
              v-stat="{
                id: CommonConfig.statData.equipmentRecord.batchDel.id,
                name: CommonConfig.statData.equipmentRecord.batchDel.name
              }"
              :disabled="selectedMachine.length === 0 ? true : false"
              >批量删除
            </q-btn>
            <download-btn
              :url="downloadUrl"
              fileName="设备台账表(模板).xls"
              :permission="Enums.SYS_PERMISSION.IMPORT_DEVICE_BTN.value"
            />
            <upload-btn
              :url="uploadUrl"
              @refresh="
                showDetailList = '';
                getList;
              "
              :permission="Enums.SYS_PERMISSION.IMPORT_DEVICE_BTN.value"
            />
            <q-btn
              v-has="{ id: Enums.SYS_PERMISSION.ADD_DEVICE_BTN.value }"
              class="btn margin-r-10"
              v-stat="{
                id: CommonConfig.statData.equipmentRecord.addMachine.id,
                name: CommonConfig.statData.equipmentRecord.addMachine.name
              }"
              outline
              color="primary"
              @click="addEquipment"
              >添加设备
            </q-btn>
            <q-btn
              v-has="{
                id: Enums.SYS_PERMISSION.PRINT_DEVICE_QR_CODE_BTN.value
              }"
              v-stat="{
                id: CommonConfig.statData.equipmentRecord.printQRCode.id,
                name: CommonConfig.statData.equipmentRecord.printQRCode.name
              }"
              class="btn margin-r-10"
              outline
              color="primary"
              @click="openPrint"
              :disabled="selectedMachine.length === 0"
              >打印二维码
            </q-btn>
            <export-btn
              :exportFun="exportFun"
              :exportParams="exportParams"
              :disable="!tableData.length"
              exportName="设备台账.xls"
            />
            <q-btn
              class="btn margin-r-10"
              outline
              color="primary"
              @click="onChangeDev"
            >车间设备排序
            </q-btn>
<!--            <span @click="onChangeDev">-->
<!--              <q-icon name="iconfont icontubiao-72" class="font-18 text-grey cursor-pointer" />-->
<!--              <q-tooltip>车间设备排序</q-tooltip>-->
<!--            </span>-->
          </div>
          <div class="right box" style="display: flex">
            <select-input
              ref="selectInput"
              :list="searchCondition"
              @search="inputSearch"
              @clearSearchVal="clearSearchVal"
            />
          </div>
        </div>
      </template>
    </collapse>
    <q-table
      :data="tableData"
      :columns="columns"
      row-key="id"
      class="myTable scroll stick-last-col"
      :loading="isTableLoading"
      :pagination.sync="pagination"
      :hide-bottom="!!tableData.length"
      selection="multiple"
      :selected.sync="selectedMachine"
      color="primary"
    >
      <template v-slot:bottom />
      <template v-slot:body-cell-isRepair="props">
        <q-td
          style="padding-left: 0;padding-right: 0;width: 18px"
          class="text-center"
        >
          <q-icon
            name="iconfont iconpingtaitubiao-52"
            class="font-18 text-primary"
            v-if="props.row.repairStatus + '' === '1'"
          >
            <q-tooltip>维修中</q-tooltip>
          </q-icon>
        </q-td>
      </template>
      <template v-slot:body-cell-status="props">
        <q-td class="record-status">
          <div
            class="indicator"
            :class="{
              negative: props.row.statusCode === 0,
              positive: props.row.statusCode === 1
            }"
          ></div>
          <span
            class="text"
            :class="{
              negative: props.row.statusCode === 0,
              positive: props.row.statusCode === 1
            }"
          >
            {{ props.row.status }}
          </span>
        </q-td>
      </template>
      <template v-slot:body-cell-operations="props">
        <q-td class="operations" style="width: 200px">
          <div class="btn-group" style="text-align: center">
            <table-btn btnType="detail" @click="detailEquipment(props.row)" />
            <table-btn btnType="edit" v-has="{ id: Enums.SYS_PERMISSION.EDIT_DEVICE_BTN.value }" @click="editEquipment(props.row)" />
            <table-btn btnType="delete" @click="deleteMachine(props.row.id)" />
            <q-toggle
              v-model="props.row.statusCode"
              :true-value="statusToggleTrueVal"
              :false-value="statusToggleFalseVal"
              checked-icon="iconfont icontubiao-49"
              unchecked-icon="iconfont icontubiao-48"
              :disable="isStatusToggleDisabled[props.row.statusCode]"
              color="positive"
              @input="onStatusToggle(props.row, $event)"
            >
              <template v-slot>
                <q-tooltip>{{ getStatusToggleTip(props.row.A) }}</q-tooltip>
              </template>
            </q-toggle>
          </div>
        </q-td>
      </template>
    </q-table>
    <div style="width: 100%;padding-top: 20px">
      <pagination
        style="position: relative;padding: 0 20px"
        v-model="pagination.page"
        :page-size="pagination.rowsPerPage"
        :total="pagination.rowsNumber"
        @changePage="onPageChange"
        @changePageSize="onPageSizeChange"
      >
      </pagination>
    </div>

    <!--新增/编辑/查看详情弹出框-->
    <record-detail
      ref="record"
      :show="equipmentDetailDialog.show"
      :for-create="equipmentDetailDialog.forCreate"
      :for-edit="equipmentDetailDialog.forEdit"
      :for-view="equipmentDetailDialog.forView"
      :equipment-type-options="equipmentTypeOptions"
      :location-options="locationOptions"
      @close="closeDialog"
      @submit="_submit"
    />

    <!--打印二维码对话框-->
    <record-qrcode
      ref="qrCode"
      :show="qrCodeShow"
      @close="qrCodeShow = false"
      :select-option="selectedMachine"
    />
    <prompt-dialog
      ref="promptDialog"
      title="确认要删除该设备吗？"
      message="删除该设备，设备相关所有信息都将被删除。"
      @onOKClick="deleteBtn"
    >
      <yz-input
        inputType="input"
        placeholder="请输入登录手机号"
        title="登录手机号"
        isRule
        :maxlength="11"
        mask="###########"
        :hintRule="[
          val =>
            userInfo.user_name + '' === val + '' || '输入内容与登录手机号不一致'
        ]"
        :rules="[0]"
        class="input-width"
        v-model="tel"
      />
    </prompt-dialog>
    <change-device-dialog ref="changeDeviceDialog" @close="getList()"/>
  </div>
</template>

<script>
import {
  addEquipment,
  batchDeletion,
  changeEquipmentStatus,
  deleteMachine,
  downloadDeviceExcel,
  EditEquipment,
  getEquipmentAccount,
  getOrganize,
  getStation
} from 'src/boot/tpm/equipment-record'
import { getDict } from 'src/boot/common/dict'
import Pagination from 'src/components/pagination'
import SelectTree from 'src/components/select-tree'
import SelectInput from 'src/components/select-input'
import RecordDetail from './components/record-detail'
import RecordQrcode from './components/record-qrCode'
import Collapse from 'src/components/collapse'
import { defaultSchemesClearer } from 'src/assets/js/util'
import { downloadTPM } from '../../boot/template/template-download'
import { uploadTPM } from '../../boot/template/template-upload'
import refreshMixin from '../../assets/js/refresh-mixin'
import { mapGetters } from 'vuex'
import promptDialog from 'src/components/prompt-dialog/prompt-dialog'
import _ from 'lodash'
import ChangeDeviceDialog from './change-device-dialog'

export default {
  name: 'equipment-record',
  mixins: [refreshMixin],
  computed: {
    ...mapGetters(['userInfo'])
  },
  components: {
    ChangeDeviceDialog,
    Pagination,
    SelectTree,
    SelectInput,
    RecordDetail,
    RecordQrcode,
    Collapse,
    promptDialog
  },
  data () {
    return {
      downloadUrl: downloadTPM, // 下载模板地址
      uploadUrl: uploadTPM, // 上传模板地址
      exportFun: downloadDeviceExcel,
      tel: '', // 登录人手机号
      qrCodeShow: false, // 打印二维码对话框显示隐藏标识
      statusToggleTrueVal: 1, // 状态 toggle 为 true 时的 status 值
      statusToggleFalseVal: 0, // 状态 toggle 为 false 时的 status 值
      isStatusToggleDisabled: {}, // 避免用户操作过快
      show: true, // 树形选择器显示隐藏标识
      selectedMachine: [], // 选中的设备台帐id
      locationOptions: [], // 所在位置数据源
      defaultStationOption: { value: null, label: '全部' },
      stationOptions: [], // 工位数据源
      defaultEquipmentTypeOption: { value: null, label: '全部' },
      equipmentTypeOptions: [], // 机床类型数据源
      // manufacturerOptions: [], // 设备厂家数据源
      // modelOptions: [], // 设备型号数据源
      tableData: [], // 列表数据源
      isTableLoading: false, // table数据列表loading动画
      searchCondition: [
        {
          id: 'number',
          name: '设备编号',
          statId: this.CommonConfig.statData.equipmentRecord.searchByNum.id
        },
        {
          id: 'name',
          name: '设备名称',
          statId: this.CommonConfig.statData.equipmentRecord.searchByName.id
        },
        {
          id: 'manufacturer',
          name: '设备厂家',
          statId: this.CommonConfig.statData.equipmentRecord.searchByFactory.id
        },
        {
          id: 'model',
          name: '设备型号',
          statId: this.CommonConfig.statData.equipmentRecord.searchByModel.id
        }
      ],
      // 表格分页配置
      pagination: {
        page: 1, // 当前页码
        rowsPerPage: 15, // 每页条数
        rowsNumber: 0 // 总条数
      },
      // 用户详情 dialog 相关数据
      equipmentDetailDialog: {
        show: false, // 显示 dialog
        forView: true, // 用于查看
        forCreate: false, // 用于创建
        forEdit: false // 用于编辑
      },
      delId: null, // 待删除id
      enabledOptions: [
        {
          value: -1,
          label: '全部'
        },
        {
          value: 1,
          label: '启用'
        },
        {
          value: 0,
          label: '禁用'
        }
      ], // 启用状态数据源
      // 查询条件
      queryParams: {
        location: {}, // 所在位置
        station: null,
        equipmentType: null,
        enabled: -1
      },
      // 表格列配置
      columns: [
        { name: 'isRepair', label: '', align: 'center', field: 'isRepair' },
        {
          name: 'assetNumber',
          label: '设备编号',
          align: 'left',
          field: 'assetNumber'
        },
        { name: 'name', label: '设备名称', field: 'name', align: 'left' },
        {
          name: 'producer',
          label: '设备厂家',
          field: 'producerStr',
          align: 'left'
        },
        {
          name: 'typeName',
          label: '设备类型',
          field: 'typeName',
          align: 'left'
        },
        { name: 'model', label: '设备型号', field: 'modelStr', align: 'left' },
        {
          name: 'deviceSpec',
          label: '设备规格',
          field: 'deviceSpecStr',
          align: 'left'
        },
        {
          name: 'ncType',
          label: '数控类型',
          field: 'ncTypeStr',
          align: 'left'
        },
        {
          name: 'workCenterName',
          label: '工位',
          field: 'workCenterName',
          align: 'left'
        },
        {
          name: 'toolMagazineCapacity',
          label: '刀库位数',
          field: 'toolMagazineCapacity',
          align: 'left'
        },
        {
          name: 'cutterGrooveNum',
          label: '刀位槽数',
          field: 'cutterGrooveNum',
          align: 'left'
        },
        {
          name: 'introduceDate',
          label: '进厂日期',
          field: 'introduceDate',
          align: 'left'
        },
        { name: 'status', label: '启用状态', field: 'status', align: 'left' },
        {
          name: 'operations',
          field: 'operations',
          label: '操作',
          align: 'center'
        }
      ],
      fileName: null, // 文件名（用于订阅）
      exportParams: {}
    }
  },
  created () {
    this.init()
  },
  methods: {
    // 设备排序
    onChangeDev () {
      this.$refs.changeDeviceDialog.initDialog()
    },
    // 初始化数据
    init () {
      this.stationOptions = [this.defaultStationOption]
      this.equipmentTypeOptions = [this.defaultEquipmentTypeOption]

      // 获取组织机构树
      getOrganize().then(res => {
        // 去除 default 节点
        let clearTree = defaultSchemesClearer.clear(res.data)

        // 重新组织 tree
        clearTree.forEach(reorganize)

        function reorganize (node) {
          // 如果当前节点是工位，将 opname 挪到 label
          if (node.level === 5) {
            node.label = node.opname
          }

          // 为节点添加唯一键，用于 tree 组件标识唯一节点
          node.uniqueKey = node.level + ':' + node.id

          if (node.children instanceof Array) {
            node.children.forEach(reorganize)
          }
        }

        this.locationOptions = clearTree
        this.selectFirstLocation()
        this.getList()
      })
      // 获取机床类型
      getDict('machine_type', false).then(res => {
        const machineTypes = res.data
        machineTypes.unshift(this.defaultEquipmentTypeOption)

        this.equipmentTypeOptions = machineTypes
      })
    },

    // 关闭弹出框
    closeDialog () {
      this.equipmentDetailDialog.show = false
    },

    // 选择组织机构树节点 *
    _changeTreeNode: function (val) {
      if (val.id && val.label && val.hash) {
        this.queryParams.location.id = val.id
        this.queryParams.location.level = val.level
        this.queryParams.location.label = val.label
        this.queryParams.location.hash = val.hash
        this.queryParams.station = null
        this.listStationOptions(val.id, val.level)
      } else {
        this.selectFirstLocation()
        this.queryParams.station = null
        this.stationOptions = [this.defaultStationOption]
      }
    },

    // 列举工位选项
    listStationOptions (schemeId, schemeLevel) {
      const options = [this.defaultStationOption]
      getStation(schemeLevel, schemeId).then(res => {
        for (const station of res.data.list) {
          options.push({
            value: station.id,
            label: station.opdesc
          })
        }
      })

      this.stationOptions = options
    },

    // 重置查询条件 *
    resetSearch () {
      this.initDict()
      this.queryParams.enabled = -1
      this.queryParams.station = null
      this.queryParams.equipmentType = null
      // this.queryParams.manufacturer = ''
      // this.queryParams.model = ''
      // this.queryParams.keyword = ''
      // this.queryParams.searchBy = ''
      this.selectedMachine = []
    },
    initDict () {
      // 获取组织机构树
      getOrganize().then(res => {
        // 去除 default 节点
        let clearTree = defaultSchemesClearer.clear(res.data)

        // 重新组织 tree
        clearTree.forEach(reorganize)

        function reorganize (node) {
          // 如果当前节点是工位，将 opname 挪到 label
          if (node.level === 5) {
            node.label = node.opname
          }

          // 为节点添加唯一键，用于 tree 组件标识唯一节点
          node.uniqueKey = node.level + ':' + node.id

          if (node.children instanceof Array) {
            node.children.forEach(reorganize)
          }
        }

        this.locationOptions = clearTree
        this.selectFirstLocation()
      })
      // 获取机床类型
      getDict('machine_type', false).then(res => {
        const machineTypes = res.data
        machineTypes.unshift(this.defaultEquipmentTypeOption)

        this.equipmentTypeOptions = machineTypes
      })
    },
    // 模糊查询
    inputSearch (item, searchVal) {
      this.pagination.page = 1
      this.queryParams.keyword = searchVal
      this.queryParams.searchBy = item.id
      this.getList()
    },

    // 清空搜索值
    clearSearchVal () {
      this.pagination.page = 1
      this.queryParams.keyword = ''
      this.queryParams.searchBy = ''
      this.$refs.selectInput.clearValue()
      this.getList()
    },

    // 获取列表数据
    getList () {
      this.selectedMachine = []
      this.isTableLoading = true
      getEquipmentAccount(
        this.queryParams.equipmentType,
        this.queryParams.keyword,
        this.queryParams.model,
        this.pagination.page,
        this.pagination.rowsPerPage,
        this.queryParams.manufacturer,
        this.queryParams.searchBy,
        this.queryParams.enabled,
        this.queryParams.station,
        this.queryParams.location.id,
        this.queryParams.location.level
      )
        .then(res => {
          const params = {
            deviceType: this.queryParams.equipmentType,
            keyword: this.queryParams.keyword,
            model: this.queryParams.model,
            producer: this.queryParams.manufacturer,
            searchBy: this.queryParams.searchBy,
            statusCode: this.queryParams.enabled,
            workCenterId: this.queryParams.station,
            schemeId: this.queryParams.location.id,
            schemeLevel: this.queryParams.location.level
          }
          this.exportParams = _.cloneDeep(params)
          if (res.data.list.length > 0) {
            for (const i of res.data.list) {
              i['statusCode'] === 0
                ? (i['status'] = '禁用')
                : (i['status'] = '启用')
              i.typeName = this.equipmentTypeOptions.find(
                item => item.value === i.typeCode
              )?.label
              // for (let j = 0; j < this.equipmentTypeOptions.length; j++) {
              //   if (i['typeCode'] === this.equipmentTypeOptions[j].value) {
              //     i['typeName'] = this.equipmentTypeOptions[j].label
              //   }
              // }
              i.producerStr = this.$utils.label(i.producer)
              i.ncTypeStr = this.$utils.label(i.ncType)
              i.modelStr = this.$utils.label(i.model)
              i.deviceSpecStr = this.$utils.label(i.deviceSpec)
            }
            this.tableData = res.data.list
          } else {
            this.tableData = []
          }
          this.pagination.rowsNumber = res.data.total
        })
        .finally(() => {
          this.isTableLoading = false
        })
    },

    // 切换每夜显示条数
    onPageSizeChange: function (val, page) {
      this.pagination.rowsPerPage = val
      page && (this.pagination.page = page)
      this.getList()
    },

    // 切换页码
    onPageChange: function (val) {
      this.pagination.page = val
      this.getList()
    },

    // 切换字典项禁用/启用状态
    onStatusToggle: function (val, status) {
      this.$set(this.isStatusToggleDisabled, val.id, true)
      changeEquipmentStatus(val.id, status)
        .then(() => {
          this.getList()
        })
        .finally(() => {
          this.$set(this.isStatusToggleDisabled, val.id, false)
        })
    },

    // 根据字典项启禁用推算toogle组件tooptip提示文字
    getStatusToggleTip: function (val) {
      return val === 0 ? '启用' : '禁用'
    },

    // 打开新增设备弹出框
    addEquipment () {
      Object.assign(this.equipmentDetailDialog, {
        forView: false,
        forCreate: true,
        forEdit: false
      })
      this.equipmentDetailDialog.show = true
      this.$refs.record.reset()
    },

    // 打开编辑设备弹出框
    editEquipment (row) {
      Object.assign(this.equipmentDetailDialog, {
        forView: false,
        forCreate: false,
        forEdit: true
      })
      this.$refs.record.assignment(row)
      this.equipmentDetailDialog.show = true
    },

    /**
     * 跳转详情传值
     * @param {{}} val
     */
    detailEquipment (val) {
      // Object.assign(this.equipmentDetailDialog, { forView: true, forCreate: false, forEdit: false })
      // this.$refs.record.assignment(val)
      // this.equipmentDetailDialog.show = true
      this.$router.push({
        name: 'equipmentRecordDetail',
        query: {
          id: val.id
        }
      })
    },
    // 批量删除
    batchDeletion () {
      this.delId = this.selectedMachine.map(o => o.id)
      this.$refs.promptDialog.show()
      // this.$q.dialog({
      //   title: `<p class="dialog-notice-title"><i class="iconfont icontubiao-28"></i>
      //     确定要删除这些项吗？</p>`,
      //   message: '删除该设备，设备相关所以信息都将被删除。',
      //   html: true,
      //   ok: {
      //     unelevated: true,
      //     label: '确认'
      //   },
      //   cancel: {
      //     unelevated: true,
      //     outline: true,
      //     label: '取消'
      //   }
      // })
      //   .onOk(() => {
      //     const query = this.selectedMachine.map(o => o.id)
      //     batchDeletion(query).then(res => {
      //       if (res.code === '1200') {
      //         this.getList()
      //         this.$message.success('删除成功')
      //       }
      //     })
      //   })
    },
    // // 删除单个设备
    // deleteMachine (id) {
    //   this.$q.dialog({
    //     title: `<p class="dialog-notice-title"><i class="iconfont icontubiao-28"></i>
    //       确定要删除此项吗？</p>`,
    //     html: true,
    //     ok: {
    //       unelevated: true,
    //       label: '确认'
    //     },
    //     cancel: {
    //       unelevated: true,
    //       outline: true,
    //       label: '取消'
    //     }
    //   })
    //     .onOk(() => {
    //       deleteMachine(id).then(res => {
    //         if (res.code === '1200') {
    //           this.getList()
    //           this.$message.success('删除成功')
    //         }
    //       })
    //     })
    // },
    // 删除单个设备
    deleteMachine (id) {
      console.log(id, 111)
      this.delId = id
      this.$refs.promptDialog.show()
    },
    deleteBtn () {
      console.log(typeof this.delId)
      if (typeof this.delId === 'object') {
        batchDeletion(this.delId)
          .then(res => {
            if (res.code === '1200') {
              this.getList()
              this.$message.success('删除成功')
            }
          })
          .finally(() => {
            this.tel = ''
            this.$refs.promptDialog.hide()
          })
      } else {
        deleteMachine(this.delId)
          .then(res => {
            if (res.code === '1200') {
              this.getList()
              this.$message.success('删除成功')
            }
          })
          .finally(() => {
            this.tel = ''
            this.$refs.promptDialog.hide()
          })
      }
    },

    // 提交表单
    _submit (forView, forCreate, forEdit, val) {
      if (forView === false && forCreate === true && forEdit === false) {
        const query = {}
        query.assetNumber = val.assetNumber || undefined
        query.documents = val.documentUrls
        query.introduceDate = val.incomingDate || undefined
        query.model = val.model || undefined
        query.deviceSpec = val.deviceSpec || undefined
        query.name = val.deviceName || undefined
        query.ncType = val.ncSystem || undefined
        query.photoUrls = [val.photoUrls]
        query.producer = val.manufacturer || undefined
        query.statusCode = val.status || undefined
        query.toolMagazineCapacity = val.toolBankNumber || undefined
        query.cutterGrooveNum = val.cutterGrooveNum || undefined
        query.typeCode = val.equipmentType || undefined
        query.workCenterId = val.station || undefined
        query.thirdId = val.thirdId
        query.schemeId = val.location.id
        query.schemeLevel = val.location.level
        addEquipment(query).then(res => {
          this.equipmentDetailDialog.show = false
          if (res.code === '1200') {
            this.getList()
            this.$message.success('添加成功')
          }
        })
      } else if (forView === false && forCreate === false && forEdit === true) {
        const query = {}
        query.assetNumber = val.assetNumber || undefined
        query.documents = val.documentUrls
        query.introduceDate = val.incomingDate || undefined
        query.model = val.model || undefined
        query.deviceSpec = val.deviceSpec || undefined
        query.name = val.deviceName || undefined
        query.ncType = val.ncSystem || undefined
        query.photoUrls = [val.photoUrls]
        query.producer = val.manufacturer || undefined
        query.statusCode = val.status || undefined
        query.toolMagazineCapacity = val.toolBankNumber || undefined
        query.cutterGrooveNum = val.cutterGrooveNum || undefined
        query.typeCode = val.equipmentType || undefined
        query.thirdId = val.thirdId
        query.schemeId = val.location.id
        query.schemeLevel = val.location.level
        query.workCenterId = val.station
        EditEquipment(query, val.id).then(res => {
          this.equipmentDetailDialog.show = false
          if (res.code === '1200') {
            this.getList()
            this.$message.success('编辑成功')
          }
        })
      }
    },
    openPrint () {
      this.qrCodeShow = true
    },

    // 选中第一个组织
    selectFirstLocation () {
      if (this.locationOptions.length === 0) {
        return
      }

      const first = this.locationOptions[0]
      this.queryParams.location.id = first.id
      this.queryParams.location.level = first.level
      this.queryParams.location.label = first.label
      this.queryParams.location.hash = first.hash
      this.$refs.selectTree.setValue(this.queryParams.location)

      this.listStationOptions(first.id, first.level)
    }
  }
}
</script>

<style scoped lang="stylus">
/deep/ .q-select__dropdown-icon {
  width 24px
  height 24px
  font-size 24px
  color rgba(0, 0, 0, .54)
}

/deep/ .pagination {
  padding 0px 50px
}

/deep/ .q-field--with-bottom {
  padding 0
}

/deep/ .q-field__marginal {
  font-size 16px
  color black
  font-weight 400
  text-align right
}

.record-status {
  .indicator {
    display inline-block
    border-radius 50%
    height 10px
    width 10px
    margin-right 2px

    &.positive {
      background $positive
    }

    &.negative {
      background $negative
    }
  }

  .text {
    &.positive {
      color $positive
    }

    &.negative {
      color $negative
    }
  }

}

.bar {
  margin-top 20px
}

.equipment-record {
  padding-top: 0px

  .toolbar .form-inline {
    display flex
    justify-content space-between

    .box {
      margin-top 20px
      display flex
      justify-content center
    }

    &.top .left {
      .select:not(:last-child) {
        margin-right 30px
        margin-bottom 5px
      }
    }

    &.bottom {
      .left {
        .btn:not(:last-child) {
          margin-right 10px
        }
      }

      .right {
        .quik-search {
          width 250px
          margin-right 10px
        }
      }
    }
  }
}
</style>

<style lang="stylus">
.equipment-record {
  .myTable .q-table__middle {
    max-height calc(100%)
  }
}
</style>
